package ua.org.oa.ishchenko;



public class App {

	public static void main(String[] args) {
		System.out.println("~~~~SimpleTask1~~~~");
		SimpleTask1 task1 = new SimpleTask1("OOracle", "AAcademy");
		task1.simpleMethod1();
		
		System.out.println("\n~~~~SimpleTask2~~~~");
		SimpleTask2 task2 = new SimpleTask2("vasya");
		task2.simpleMethod2();
		
		System.out.println("\n~~~~SimpleTask3~~~~");
		SimpleTask3 task3 = new SimpleTask3("sergey");
		task3.simpleMethod3();
		
		System.out.println("\n~~~~MiddleTask4~~~~");
		MiddleTask4 task4 = new MiddleTask4("Oracle");
		task4.middleMethod4();
		
		System.out.println("\n~~~~MiddleTask5~~~~");
		MiddleTask5 task5 = new MiddleTask5("bubbles , bible, rubob ");
		task5.middleMethod5();
		
		System.out.println("\n~~~~MiddleTask6~~~~");
		MiddleTask6 task6 = new MiddleTask6("moo*mment morg*he");
		task6.middleMethod6();
		
		System.out.println("\n~~~~HardTask7~~~~");
		HardTask7 task7 = new HardTask7("I lean Java Fundamentals every months, every days.");
		task7.hardMethod7();
		
		System.out.println("\n~~~~HardTask8~~~~");
		HardTask8 task8 = new HardTask8("Java is not hard", "not");
		task8.hardMethod8();
	}	
		
	}

class SimpleTask1 {
		private String string1;
		private String string2;

		public SimpleTask1(String str1, String str2) {
			this.string1 = str1;
			this.string2 = str2;
		}

		public void simpleMethod1() {
			System.out.println("First string: " + string1);
			System.out.println("Second string: " + string2);
			System.out.println("Result string: " + string1.substring(1) + string2.substring(1) );

		}
}

class SimpleTask2{
		private String startString = null;
		private String resultString = null;
		
		public SimpleTask2(String startString){
			this.startString = startString;
		}	
			public void simpleMethod2() {
			System.out.println("Start string: " + startString);
		if(startString.length() % 2 != 0 & startString.length() >= 3){
			resultString = startString.substring((startString.length())/2-1, (startString.length()) / 2 + 2);
			
			System.out.println("Result string: " + resultString);
		}
		else {
			System.out.println("Invalid input");
			}
		
		}
	
}

class SimpleTask3{
		private String startString = null;
		private String resultString = null;
		
		public SimpleTask3(String startString){
			this.startString = startString;
		}	
		public void simpleMethod3() {
			System.out.println("Start string: " + startString);
			if(startString.length() >= 2){
			resultString = startString.substring(startString.length()-2);
			System.out.println("Result string: " + resultString);
		}
			else {
				System.out.println("Invalid input");
			}
		}
}

class MiddleTask4{
	private String startString = null;
	private String resultString = null;
	
	public MiddleTask4(String startString) {
		this.startString = startString;
	}
	
	public void middleMethod4(){
		StringBuilder strb = new StringBuilder(startString);
		System.out.println("Start string: " + startString);
		for (int i = 0; i < strb.length(); i+=2) {
			strb = strb.insert(i, strb.charAt(i));
			resultString = strb.toString();
			
		}
		System.out.println("Result string: " + resultString);
			
		}
	}
		
class MiddleTask5{
	private String startString = null;
	
	public MiddleTask5(String startString){
		this.startString = startString;
	}
		
		public void middleMethod5(){
		int summ = 0;
		System.out.println("Start string: " + startString);
		for (int i = 0; i < startString.length() - 2; i++) {
			if((startString.charAt(i) == 'b' )&&( startString.charAt(i + 2) == 'b')){
				summ ++;
			}
			
			
			
		}	
		System.out.println("The number of occurrences: " + summ);
		}
}

class MiddleTask6{
	private String startString = null;
	private String resultString = null;
	
	public MiddleTask6(String startString){
		this.startString = startString;
	}
		
		public void middleMethod6(){
		
		System.out.println("Start string: " + startString);
		StringBuilder strb = new StringBuilder(startString);
		
		for (int i = 0; i < strb.length() - 1; i++) {
			if(strb.charAt(i) == '*' ){
				
				strb.delete(i-1, i+2);
							
			}
						
		}
		resultString = strb.toString();
		System.out.println("Result string: " + resultString);
		}
}

class HardTask7{
	private String startString = null;
	private String resultString = null;
	
	public HardTask7(String startString){
		this.startString = startString;
	}
		
		public void hardMethod7(){
		
		System.out.println("Start string: " + startString);
		StringBuilder strb = new StringBuilder(startString);
		int summ = 0;
		for (int i = 0; i < strb.length() - 1; i++) {
			
			if((strb.charAt(i) == 'a' )&& (strb.charAt(i + 1) == ' ') || (strb.charAt(i + 1) == '.') || ((strb.charAt(i + 1) == ',') )){
					//strb.charAt(i) == 's' && strb.charAt(i + 1) == ' '){
				summ++;
			}
			else if ((strb.charAt(i) == 's') && (strb.charAt(i + 1) == ' ') || (strb.charAt(i + 1) == '.') || ((strb.charAt(i + 1) == ',') )){
		summ++;
		}
		
}
		System.out.println("Words: " + summ);
		}		
}

class HardTask8{
	private String startString1 = null;
	private String startString2 = null;
	private String resultString = null;
	
	public HardTask8(String startString1,String  startString2){
		this.startString1 = startString1;
		this.startString2 = startString2;
	}
		
		public void hardMethod8(){
			System.out.println("Start string1: " + startString1);
			System.out.println("Start string2: " + startString2);
			resultString = startString1.replace(startString2, "");
			System.out.println("Result string: " + resultString);
			
			
		}
}